<?php
namespace app\crm\model;
use think\Model;
use think\model\concern\SoftDelete;

class User extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    protected $globalScope = ['shop_id'];
    
    public function scopeShop_id($query)
    {
        $query->where('shop_id', ShopId());
    }

    public function userGroup()
    {
        return $this->belongsTo(\app\user\model\UserGroup::class, 'group_id', 'id')->bind(['rules','group_name'=>'name']);
    }
    public function shop()
    {
        return $this->belongsTo(\app\user\model\Shop::class, 'shop_id', 'id');
    }
    
    //关联统计客户数
    public function customer()
    {
        return $this->hasMany(CrmUser::class, 'user_id', 'id')->where('status','1');
    }
    //关联统计回访
    public function track()
    {
        return $this->hasMany(CrmTrack::class, 'user_id', 'id');
    }
    //关联统计回访
    public function sales()
    {
        return $this->hasMany(CrmSales::class, 'user_id', 'id');
    }
    //关联统计回访
    public function contract()
    {
        return $this->hasMany(CrmContract::class, 'user_id', 'id');
    }
    
}